

IF EXISTS (SELECT * FROM DBO.SYSOBJECTS WHERE NAME='SP_CAPNHATNHANVIEN')
BEGIN
	DROP PROC  SP_CAPNHATNHANVIEN
END
GO
CREATE PROC  SP_CAPNHATNHANVIEN
	@HONV	NVARCHAR(10),
	@TENLOT	NVARCHAR(10),
	@TENNV	NVARCHAR(10),
	@MANV	NVARCHAR(10),
	@NGSINH	DATETIME,
	@DCHI	NVARCHAR(100),
	@PHAI	NCHAR(3),
	@LUONG	NUMERIC,
	@MA_NQL	VARCHAR(10),
	@PHG	INT,
	@MANV	NVARCHAR(10),
	@STATUS	INT OUTPUT
AS
BEGIN
	IF EXISTS (SELECT * FROM NHANVIEN WHERE MANV=@MANV)
	BEGIN
-- NHAN VIEN DA TON TAI
		UPDATE 	NHANVIEN
		SET HONV	=	@HONV,
			TENLOT	=	@TENLOT, 
			TENNV	=	@TENNV,
			MANV	=	@MANV,
			NGSINH	=	@NGSINH,
			DCHI	=	@DCHI,
			PHAI	=	@PHAI,
			LUONG	=	@LUONG,
			MA_NQL	=	@MA_NQL,
			PHG		=	@PHG 
		WHERE MANV	=	@MANV
	SET	@STATUS = 1 
	PRINT 'NHAN VIEN DA TON TAI'
	END
	ELSE
	BEGIN
-- NHANVIEN CHUA TON TAI
	INSERT INTO NAHNVIEN
	VALUES(@HONV,
		@TENLOT,
		@TENNV,
		@MANV,
		@NGSINH,
		@DCHI,
		@PHAI,
		@LUONG,
		@MA_NQL,
		@PHG)		
	SET @STATUS=0
		PRINT 'NHAN VIEN KHONG TON TAI'
	END 
END
/*-- EXECUTE
DECLARE @RESULT INT
EXEC SP_KIEMTRANHANVIEN '123123456',@RESULT OUTPUT
SELECT @RESULT AS 'RESULT'
*/